<?php
class OORDBMySQLQuery implements OORDBQuery
{
	private $result;
	private $sql;
	private $connection;
	
	/**
	 * Construct a generic query object with a MySQL connection resource.
	 * @param resource $connection $mysqlConnection
	 */
	public function __construct( $connection )
	{
		$this->connection = $connection;
	}
	
	public function setSQL( $sql )
	{
		$this->sql = $sql;
	}
	
	public function execute()
	{
		$this->result = mysql_query( $this->sql, $this->connection );
		if ( $this->result === false )
		{
			throw new OORDBQueryException( mysql_error(), $this->sql );
		}
	}
	
	protected function getResult()
	{
		return $this->result;
	}
	
	/**
	 * Escape a string to insert into a SQL query.
	 * @param string $string String to escape
	 * @return string Escaped string
	 */
	public function escape( $string )
	{
		return mysql_real_escape_string( $string, $this->connection );
	}
}
?>